<?php
/* This file receives update requests, insert requests and deals with people trying to access the action.php by redirecting them to the index file.
 */
include_once("conf.php");
include_once("functions.php");

if(isValidForInsertion($_POST)){ //If post parameters are valid for insertion
	logError("Someone made a request with post parameters valid for insertion"); // Log it
	echo json_encode(insertIntoDb($_POST), JSON_FORCE_OBJECT); // Answer with the result of the insertion
} else if(isset($_POST["getUpdate"]) && $_POST["getUpdate"] == "true"){ // Else, if the resquest asks for an update
	logError("Received an update request"); // log it
	echo json_encode(getRetards(), JSON_FORCE_OBJECT); // And answers with everything that can be fetched from the database
} else { // Else, someone is trying to access the file without asking for either an insertion or an update
	logError("Someone tried to connect to action.php without setting POST parameters."); //log it
	echo json_encode(false); // Tell him that he's wrong
	header("location: ."); // redirect him to the index file
}
?>